package org.fixies.spreadsheet.converter;

import org.fixies.spreadsheet.Cell;
import org.fixies.spreadsheet.ParameterMap;
import org.fixies.spreadsheet.Row;
import org.fixies.spreadsheet.Unit;

import java.util.Iterator;


public class ParameterMapConverter extends AbstractDataSetConverter<ParameterMap> {

    @Override
    public ParameterMap convert() {
        Unit unit = getDataSet();
        // 結果
        ParameterMap result = new ParameterMap();

        Iterator<Row> itr = unit.iterator();
        if (!itr.hasNext()) {
            return result;
        }

        // 一行目は見出し（キー）
        Row midashi = itr.next();
        Row dataRow = itr.next();

        for (int i = 0; i < midashi.size(); i++) {
            String key = midashi.get(i).asString();
            Cell value = dataRow.get(i);
            result.put(key, value);
        }
        return result;
    }
}
